/**
 *
 */
//项目名称
var proName = "";
//ajax操作状态：0：未请求，1：请求中
var ajaxState = 0;
var meeting = {
    webSite: {
        pro: "",
        host: window.location.host,
        protocol: window.location.protocol,
        fullhost: function () {
            return window.location.protocol + "//" + window.location.host + ($.trim(proName) == "" ? "" : proName + "/");
        }
    },
    security: {
        dialog: function (option) {
            var panelHtml = "<div><lable>口令：</label></span><input type='password' id='pwd' /></span></div>";

            art.dialog({
                id: "securityDialog",
                title: "管理员口令",
                icon: "face-smile",
                content: panelHtml,
                ok: function () {
                    var pwd = $(this.content()).find("#pwd").val();
                    meeting.security.verify(option, pwd);
                    return false;
                },
                cancel: false
            });
        },
        verify: function (option, password) {
            var defaultOption = {
                securityUrl: "/comsys/sys/security/verify",
                serverUrl: "",
                param: "",
                callback: function (data) {
                }
            }

            $.extend(defaultOption, option);

            $.ajax({
                type: "POST",
                url: defaultOption.securityUrl,
                data: {
                    password: password,
                    serverUrl: defaultOption.serverUrl,
                    param: defaultOption.param
                },
                success: function (data) {
                    defaultOption.callback(data);
                },
                error: function (x) {
                    console.log(x.responseText);
                }
            });
        }
    },
    ajax: function (url, successfun, option, errorfun, isvalid) {
        if (isvalid != 0) {
            if (ajaxState == 1) {
                $.confirm({
                    title: "提示",
                    content: "操作频繁，请稍后再试...",
                    autoClose: "close|2000",
                    buttons: {
                        close: {
                            text: "关闭",
                            action: function () {
                                self.close();
                            }
                        }
                    }
                })

                return;
            }
        }

        ajaxState = 1;
        var defaultOption = {
            url: url,
            type: 'POST',
            dataType: "json",
            success: function (result) {
                ajaxState = 0;
                if ($.isFunction(successfun)) {
                    successfun(result);
                }
            },
            error: function (x) {
                ajaxState = 0;
                if ($.isFunction(errorfun)) {
                    errorfun(x);
                } else {
                    console.log(x);
                }
            }
        }

        $.extend(true, defaultOption, option);

        $.ajax(defaultOption);
    }
}
